<!DOCTYPE html>
<html>
<head><title>System Report</title><head>

<body>
<fieldset> 
<legend>System Report</legend>

	
<?php include("../db.php");

session_start();
check_inactive();
authenticate_admin();

$db=pg_connect("host=dbsrv1 dbname=csc309g7 user=csc309g7 password=aiboid4p");


if (!$db) 
{
	echo "db connection failed";
}

$total_game=pg_query("SELECT COUNT(gameid) FROM games");
$total_unfinished_game=pg_query("SELECT * FROM games WHERE start_date>=CURRENT_DATE;");
$game_type=pg_query("SELECT sid,duration FROM sports; "); //get id by duration
$count=0;


$account=pg_query("SELECT COUNT(username) FROM people");

if ($db)
{

echo "<table border='1'><tr><strong></strong></tr>";
echo "<tr><td><strong>Accounts</strong></td></tr>";
echo "<tr><td>"; /*statistic value for account*/		
		if (!account)
			{
				echo"Accounts are not retrievable \n";
				exit;
			}
		else
			{
			$total_account=pg_fetch_assoc($account);
			
			echo "Total Accounts: ".$total_account['count']; 
			}
echo "</td></tr>";


echo "<tr><td><strong>Games</strong></td></tr>";
echo "<tr><td>";
	
		if (!$total_game)
			{
				print "Games are not retrievable \n";
				exit;
			}
		else {
			$t_game=pg_fetch_assoc($total_game);
			echo "Total Games: " .$t_game['count'];
			}
echo "</td></tr>";

echo "</table>";
}/*end of if($db)*/

?>


</fieldset>
</body>
</html>
